//
//  LeftPageViewController.m
//  Alltelevisionnews
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "LeftPageViewController.h"
#import "GraphicViewController.h"
#import "SLVideoPageViewController.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height

@interface LeftPageViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong) UITableView *tableView;

@end

@implementation LeftPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //给view添加一个背景图片
//   UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds];
    UIImageView *imageview = [[UIImageView alloc] init];
    imageview.image = [UIImage imageNamed:@"leftpage.png"];
    [self.view addSubview:imageview];
    [imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.and.bottom.and.right.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0));
        
        
    }];

    
    //创建左侧的视图的tableView
    UITableView *tableView = [[UITableView alloc] init];
    self.tableView = tableView;
//    tableView.frame = self.view.bounds;
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableView];
    
}

- (void)viewDidDisappear:(BOOL)animated {
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.and.left.and.bottom.and.right.equalTo(self.view).insets(UIEdgeInsetsMake(0, 50, 0, 50));
        
    }];

    
    
}


#pragma mark  -- dataSource和delegate


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 5;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    static NSString *Indentifier = @"Indentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Indentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Indentifier];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont systemFontOfSize:20.0f];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor blackColor];
    if (indexPath.row == 0) {
        cell.textLabel.text = @"新闻";
    } else if (indexPath.row == 1) {
        cell.textLabel.text = @"图文";
    } else if (indexPath.row == 2) {
        cell.textLabel.text = @"视听";
    } else if (indexPath.row == 3) {
        cell.textLabel.text = @"专题";
    }else {
        
        cell.textLabel.text = @"我的";
        
    }
    
    return cell;

    
}


#pragma mark tableView的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    //关闭左侧抽屉
    [tempAppDelegate.leftslideVC closeLeftView];
    
    if (indexPath.row == 0) {
        ViewController *view = [[ViewController alloc] init];
        [tempAppDelegate.mainNavigationController pushViewController:view animated:NO];
    } else if (indexPath.row == 1) {
        
        GraphicViewController *graphicVC = [[GraphicViewController alloc] init];
        [tempAppDelegate.mainNavigationController pushViewController:graphicVC animated:NO];
        
    } else if (indexPath.row == 2) {
        
        SLVideoPageViewController *audio = [[SLVideoPageViewController alloc] init];
        [tempAppDelegate.mainNavigationController pushViewController:audio animated:NO];
        
    } else if (indexPath.row == 3) {
        
        TopicsViewController *topicVC = [[TopicsViewController alloc] init];
        [tempAppDelegate.mainNavigationController pushViewController:topicVC animated:NO];
        
    } else {
        
        MainViewController *main = [[MainViewController alloc] init];
        [tempAppDelegate.mainNavigationController pushViewController:main animated:NO];
        
    }
 
}



#pragma mark设置分区的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 200 * HEIGHT / 667;
    
}


#pragma mark 设置分区
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 100 * HEIGHT / 667)];
    view.backgroundColor = [UIColor clearColor];
    return view;
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
